var idcard = 0;
var ph = 0;
//点击获取单个老师id
var teacher;
//点击获取老师名字
var teachername;
//存储导师的信息
var teacher_data = [];
//*************************************************************
//《《三级联动》》
$.each(AreaListData, function(k, v) {
	if(v[1] == 0) {
		var option = "<option value='" + k + "'>" + v[0] + "</option>";
		$('#kechengpeixun>article>.cha>.sj>h2>#province').append(option);
	}
});
$('#kechengpeixun>article>.cha>.sj>h2>#province').change(function() {
	$('#kechengpeixun>article>.cha>.sj>h2>#city option:gt(0)').remove();
	$('#kechengpeixun>article>.cha>.sj>h2>#district option:gt(0)').remove();
	var sheng = $(this).val();
	$.each(AreaListData, function(k, v) {
		if(v[1] == sheng) {
			var option = "<option value='" + k + "'>" + v[0] + "</option>";
			$('#kechengpeixun>article>.cha>.sj>h2>#city').append(option);
		}
	});
});
$('#kechengpeixun>article>.cha>.sj>h2>#city').change(function() {
	$('#kechengpeixun>article>.cha>.sj>h2>#district option:gt(0)').remove();
	var shi = $(this).val();
	var f = 1;
	$.each(AreaListData, function(k, v) {
		if(v[1] == shi) {
			var option = "<option value='" + k + "'>" + v[0] + "</option>";
			$('#kechengpeixun>article>.cha>.sj>h2>#district').append(option);
			if(f) {
				$('#kechengpeixun>article>.cha>.sj>h2>#district').show();
			}
			f = 0;
		}
		if(f) {
			$('#kechengpeixun>article>.cha>.sj>h2>#district').empty();
			$('#kechengpeixun>article>.cha>.sj>h2>#district').hide();
		}
	})
})

//********************导师详情页支付*********************

$(function() {
	//模糊图层
	var mohu = $("#xing>article>h1");
	//都买过的
	//余额
	var yue = "";
	//导师详情价格
	var jiage = $("#xing>article>.daoshixiang>p>span").text()*1;
	//当点击支付查看详情时
	$("#xing>article>button").click(function() {
		mohu.show();
		$("#xing>article>.daoshixiang").show();
	});
        
    
	$("#xing>article>.daoshixiang>a").click(function() {
		new Ajax("/account/yue").keyvalue("myid", RssUser.Data.myid).getJson(function(data) {
			yue = data[0].availablefunds*1;
			if(yue <= jiage) {
				$("#xing>article>.daoshixiang").hide();
				$("#xing>article>.yuebu").show();
			} else {
				$("#xing>article>.daoshixiang").hide();
				$("#xing_zhifu").show();
			}
		})
	})
	//选择是否支付
	$("#xing_zhifu>p>b:first-of-type").click(function() {
		new Ajax("/order/buy").keyvalue("teacherid", teacher).keyvalue("teachername", teachername).keyvalue("target", "datateacher").get(function(data) {
			if(data == 6) {
				$(" #xing>article>.zu").show();
				$("#xing_zhifu").hide();
				$("#xing>article>.daoshixiang").hide();
			}
		})

	})
	$("#xing_zhifu>p>b:last-of-type").click(function() {
		$("#xing_zhifu").hide();
		$("#xing>article>.daoshixiang").hide();
		mohu.hide();
	})
	//购买成功点击确认
	$("#xing>article>.zu").find("a").click(function() {
		mohu.hide();
		var sex;
		$("#xing>article>.zu").hide();
		$.each(teacher_data, function(key, val) {
			if(val.sex == "1") {
				sex = "男";
			} else {
				sex = "女";
			}
			if(val.id == teacher) {
				$("#xing>article>form>ul").empty();
				$("#xing>article>form>ul").append("<li>" + "姓名：" + val.name + "</li>" + "<li>" + "性别：" + sex + "</li>" + "<li>" + "年龄：" + val.nianling + "</li>" + "<li>" + "身份证号：" + val.idcard + "</li>" + "<li>" + "联系电话：" + val.telphone + "</li>" + "<li>" + "证书编号：" + val.bianhao + "</li>" + "<li>" + "专业领域：" + val.zhuanye + "</li>");
			}
		});
		$("#xing").find("button").hide();
	})
	//前往支付界面点击取消
		$("#xing>article>.yuebu>p>b").click(function() {
			$("#xing>article>.yuebu").hide();
			mohu.hide();
		})
	//获取查询导师的下拉框
	$("#kechengpeixun>article>.cha>.mz>h1>.xiala").change(function() {
		if($(this).val() == "diqu") {
			$("#kechengpeixun>article>.cha>.sj").show();
			$("#kechengpeixun>article>.cha>.nr").hide();
		} else {
			$("#kechengpeixun>article>.cha>.sj").hide();
			$("#kechengpeixun>article>.cha>.nr").show();
		}

	})
	//获取button按钮  
	$("#kechengpeixun>article>.cha>.chaxun>button").click(function() {
		//获取选择框的值
		var sle = $("#kechengpeixun>article>.cha>.mz>h1>.xiala").val();
		//获取输入框的值
		var inp = $("#kechengpeixun>article>.cha>.nr>input").val();
		if(sle == "diqu") {

			//省市县
			var sheng = $("#kechengpeixun>article>.cha>.sj>h2>select>#province").val();
			var shi = $("#kechengpeixun>article>.cha>.sj>h2>select>#city").val();
			var xian = $("#kechengpeixun>article>.cha>.sj>h2>select>#district").val();
			new Ajax("/daoshi").keyvalue({
				"leibie": "diqu",
				"shengid": sheng,
				"shiid": shi,
				"xianid": xian
			}).getJson(function(json) {
				teacher_data = [];
				$.each(json, function(k, v) {
					teacher_data.push(v);
					$("#xing>article>form>ul").empty();
					$("#qunbu>article>ul").empty();
					$("#qunbu>article>ul").append("<li>" + "<img src=" + http + v["ico"] + ">" + "<div>" + "<h2>" + v["name"] + "</h2><a href=#xing>" + "<h4 teacher=" + v["id"] + " mingzi=" + v["name"] + ">" + " " + "</h4>" + "</a>" + "</div>" + "</li>");
				})
			})
		} else {
			var typ = "";
			typ = panduan(sle, typ);
			new Ajax("/daoshi").keyvalue({
				"leibie": typ,
				"name": inp
			}).getJson(function(json) {
				teacher_data = [];
				$.each(json, function(k, v) {
					teacher_data.push(v);
					$("#xing>article>form>ul").empty();
					$("#qunbu>article>ul").empty();
					$("#qunbu>article>ul").append("<li>" + "<img src=" + http + v["ico"] + ">" + "<div>" + "<h2>" + v["name"] + "</h2><a href=#xing>" + "<h4 teacher=" + v["id"] + " mingzi=" + v["name"] + ">" + "查看详情" + "</h4>" + "</a>" + "</div>" + "</li>");
					idcard = v['idcard'];
					ph = v['telphone'];
				})
			})
		}
	})
	//点击查看老师详情页
	$("#qunbu>article>ul").on("click", "h4", function() {
		$("#xing>article>form>ul").empty();
		//获取老师id
		teacher = $(this).attr("teacher");
		teachername = $(this).attr("mingzi");
		//讲师性别
		var sex;
		new Ajax("/teacher").keyvalue("myid", RssUser.Data.myid).keyvalue("teacherid", teacher).get(function(json) {
			if(teacher_data["sex"] == "1") {
				sex = "男";
			} else {
				sex = "女";
			}
			if(json == "1") {
				$.each(teacher_data, function(key, val) {
					if(val.id == teacher) {
						$("#xing>article>form>ul").append("<li>" + "姓名：" + val.name + "</li>" + "<li>" + "性别：" + sex + "</li>" + "<li>" + "年龄：" + val.nianling + "</li>" + "<li>" + "身份证号：" + val.idcard + "</li>" + "<li>" + "联系电话：" + val.telphone + "</li>" + "<li>" + "证书编号：" + val.bianhao + "</li>" + "<li>" + "专业领域：" + val.zhuanye + "</li>");
					}
				});
				$("#xing").find("button").hide();

			} else {
				$.each(teacher_data, function(key, val) {
					if(val.id == teacher) {
						$("#xing>article>form>ul").append("<li>" + "姓名：" + val.name + "</li>" + "<li>" + "性别：" + sex + "</li>" + "<li>" + "年龄：" + val.nianling + "</li>" + "<li>" + "身份证号：" + val.idcard.substring(0, 5) + "******" + val.idcard.substring(14) + "</li>" + "<li>" + "联系电话：" + val.telphone.substring(0, 5) + "******" + val.telphone.substring(7) + "</li>" + "<li>" + "证书编号：" + val.bianhao + "</li>" + "<li>" + "专业领域：" + val.zhuanye + "</li>");
					}
				});
              $("#xing").find("button").show();
			}
		})
	})

	function panduan(v, t) {
		switch(v) {
			case "name":
				t = "name";
				break;
			case "idcard":
				t = "idcard";
				break;
			case "bianhao":
				t = "bianhao";
				break;
			case "diqu":
				t = "diqu";
				break;
		}
		return t;
	}
})
$(function () {
    new uploadPreview({UpBtn: "ico", DivShow: "goods_logo_dv", ImgShow: "goods_logo_im"});
    $("#apply>article>from>ul>li:nth-child(9) input").on("change",function(){
        var value = $(this).val();
        if(value){
            $("#apply>article>from>ul>li:nth-child(9) div").show();
        }else{
            $("#apply>article>from>ul>li:nth-child(9) div").hide();
        }
    })
})
$(function(){
    $("#apply>article>button").on("click",function(){
        new Ajax("/teacher_aply").getJson(function(json){
            $.each(json, function(k, v){
                alert(v);
                $("input[name='name']").val(v["name"]);
                
                $("input[name='sex']").val(v["sex"]);
                $("input[name='nianling']").val(v["nianling"]);
                $("input[name='idcard']").val(v["idcard"]);
                $("input[name='telphone']").val(v["telphone"]);
                $("input[name='bianhao']").val(v["bianhao"]);
                $("input[name='zhuanye']").val(v["zhuanye"]);
            })
        })
    })
})

//********************导师注册****************************
$.each(AreaListData, function(k, v) {
	if(v[1] == 0) {
		var option = "<option value='" + k + "'>" + v[0] + "</option>";
		$('#apply>article>from>ul>li:nth-child(8) #province').append(option);
	}
});
$('#apply>article>from>ul>li:nth-child(8) #province').change(function() {
	$('#apply>article>from>ul>li:nth-child(8) #city option:gt(0)').remove();
	$('#apply>article>from>ul>li:nth-child(8) #district option:gt(0)').remove();
	var sheng = $(this).val();
	$.each(AreaListData, function(k, v) {
		if(v[1] == sheng) {
			var option = "<option value='" + k + "'>" + v[0] + "</option>";
			$('#apply>article>from>ul>li:nth-child(8) #city').append(option);
		}
	});
});
$('#apply>article>from>ul>li:nth-child(8) #city').change(function() {
	$('#apply>article>from>ul>li:nth-child(8) #district option:gt(0)').remove();
	var shi = $(this).val();
	var f = 1;
	$.each(AreaListData, function(k, v) {
		if(v[1] == shi) {
			var option = "<option value='" + k + "'>" + v[0] + "</option>";
			$('#apply>article>from>ul>li:nth-child(8) #district').append(option);
			if(f) {
				$('#apply>article>from>ul>li:nth-child(8) #district').show();
			}
			f = 0;
		}
		if(f) {
			$('#apply>article>from>ul>li:nth-child(8) #district').empty();
			$('#apply>article>from>ul>li:nth-child(8) #district').hide();
		}
	})
})
$.each(AreaListData, function(k, v) {
	if(v[1] == 0) {
		var option = "<option value='" + k + "'>" + v[0] + "</option>";
		$('#apply>article>from>ul>li:nth-child(8) #province').append(option);
	}
});
$('#apply>article>from>ul>li:nth-child(8) #province').change(function() {
	$('#apply>article>from>ul>li:nth-child(8) #city option:gt(0)').remove();
	$('#apply>article>from>ul>li:nth-child(8) #district option:gt(0)').remove();
	var sheng = $(this).val();
	$.each(AreaListData, function(k, v) {
		if(v[1] == sheng) {
			var option = "<option value='" + k + "'>" + v[0] + "</option>";
			$('#apply>article>from>ul>li:nth-child(8) #city').append(option);
		}
	});
});
$('#apply>article>from>ul>li:nth-child(8) #city').change(function() {
	$('#apply>article>from>ul>li:nth-child(8) #district option:gt(0)').remove();
	var shi = $(this).val();
	var f = 1;
	$.each(AreaListData, function(k, v) {
		if(v[1] == shi) {
			var option = "<option value='" + k + "'>" + v[0] + "</option>";
			$('#apply>article>from>ul>li:nth-child(8) #district').append(option);
			if(f) {
				$('#apply>article>from>ul>li:nth-child(8) #district').show();
			}
			f = 0;
		}
		if(f) {
			$('#apply>article>from>ul>li:nth-child(8) #district').empty();
			$('#apply>article>from>ul>li:nth-child(8) #district').hide();
		}
	})
})
//*****************************导师申请结束********************************